//
//  ClassroomViewController.m
//  AnXin100
//
//  Created by 王合润 on 10/24/18.
//  Copyright © 2018 tzhg. All rights reserved.
//

#import "ClassroomViewController.h"
#import "ClassroomListViewController.h"
#import "ClassroomDetailViewController.h"
#import "XXPageTabView.h"
#import "XJAVPlayer.h"
#import "ZXCategories.h"

@interface ClassroomViewController ()

@property (nonatomic, strong) XXPageTabView *pageTabView;

//@property (nonatomic, strong) SDCycleScrollView *headImageView;

@property (nonatomic, strong) XJAVPlayer *myPlayer;
@property (nonatomic, strong) UIScrollView *scroll;

@end

@implementation ClassroomViewController

- (void)viewDidLoad {
    
    [self setupNavigationItems];
    [PublicMonMethods settitle:@"种植技术" viewController:self];
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.myPlayer];
    [self.view addSubview:self.pageTabView];
    
}

- (XXPageTabView *)pageTabView
{
    if (!_pageTabView) {
        
        
        ClassroomDetailViewController *vc1 = [[ClassroomDetailViewController alloc] initWithNibName:@"ClassroomDetailViewController" bundle:[NSBundle mainBundle]];
        [self addChildViewController:vc1];
        
        ClassroomListViewController *vc2 = [[ClassroomListViewController alloc] init];
        [self addChildViewController:vc2];
        
        //支持网易云音乐，今日头条，微博等切换栏效果
        _pageTabView = [[XXPageTabView alloc] initWithChildControllers:self.childViewControllers childTitles:@[@"详情",@"课堂目录"]];
        _pageTabView.frame = CGRectMake(0, CGRectGetMaxY(_myPlayer.frame), Wi, Hi-CGRectGetMaxY(_myPlayer.frame));
        
        _pageTabView.selectedTabIndex = 0;
        _pageTabView.maxNumberOfPageItems = 2;
        _pageTabView.tabSize = CGSizeMake(Wi, 44);
        _pageTabView.tabItemFont = FONT_FOURTEEN;
        /** 适配 */
        if (SCREEN_WIDTH <= 375) {
            
            _pageTabView.tabItemFont = FONT_TWELVE;
        }
        
        _pageTabView.unSelectedColor = White(50);
        _pageTabView.selectedColor = COLOR_GREEN;
        
        _pageTabView.tabBackgroundColor = White(250);
        
        //_pageTabView.separatorColor = [[UIColor grayColor] colorWithAlphaComponent:0.4];
        _pageTabView.bodyBounces = NO;
        
        _pageTabView.indicatorWidth = 0;
        _pageTabView.indicatorHeight = 2;
        
        _pageTabView.delegate = self;
        _pageTabView.titleStyle = XXPageTabTitleStyleDefault;
        _pageTabView.indicatorStyle = XXPageTabIndicatorStyleDefault;
        
        UIScrollView *bodyView = [_pageTabView valueForKey:@"bodyView"];
        [bodyView.panGestureRecognizer requireGestureRecognizerToFail:self.navigationController.interactivePopGestureRecognizer];
    }
    return _pageTabView;
}



- (XJAVPlayer *)myPlayer {
    if (!_myPlayer) {
        _myPlayer = [[XJAVPlayer alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 300)];
        _myPlayer.delegate = self;
        _myPlayer.xjPlayerUrl = @"http://static.tripbe.com/videofiles/20121214/9533522808.f4v.mp4";
        
    }
    return _myPlayer;
}


//- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
//    //如果添加了自动缩到右下角，在scrollView的代理里面还在加上这句；
//    if (scrollView.contentOffset.y - _myPlayer.originalFrame.origin.y <= 0) {
//        [_myPlayer movieXJPlayeToOriginalPosition];
//        [scrollView addSubview:_myPlayer];
//    }
//}


- (void)setupNavigationItems {
    
    /** 导航条左边的按钮 */
    //返回按钮
    UIButton *kfBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [kfBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    kfBtn.frame = CGRectMake(0, 0, 30, 30);
    [kfBtn addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithCustomView:kfBtn];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    UILabel *titleLabel = [[UILabel alloc]init];
    titleLabel.textColor = [UIColor colorWithHex:0x29b566];
    titleLabel.text = @"种植技术";
    self.navigationItem.titleView = titleLabel;
    
}

#pragma mark - Action

- (void)backAction:(UIBarButtonItem *)item {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)search:(UIButton *)btn {
    
}

#pragma mark - xjAVPlayer代理
- (void)nextXJPlayer{
    
   _myPlayer.xjPlayerUrl = @"http://www.jxgbwlxy.gov.cn/tm/course/041629011/sco1/1.mp4";
}

- (void)xjPlayerFullOrSmall:(BOOL)flag{
    
    //如果xjPlayer的界面有导航栏或者有tabbar,在全屏代理方法里全屏时进行如下隐藏；
    if (flag) {
        self.navigationController.navigationBarHidden = YES;
        self.tabBarController.tabBar.hidden = YES;
    }else{
        self.navigationController.navigationBarHidden = NO;
        self.tabBarController.tabBar.hidden = YES;
    }
    
    if (flag) {
        /**
         *  全屏时隐藏顶部状态栏。由于iOS7.0后，如果你的plist文件已经设置View controller-based status bar appearance，value设为NO，就不用写下面的代码（我已经封装好）,如果没设置，就把下面的代码放开，就能在全屏时隐藏头部状态栏；
         */
        //        [[UIApplication sharedApplication] setStatusBarHidden:YES];
    }else{
        //        [[UIApplication sharedApplication] setStatusBarHidden:NO];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}



@end
